#ifndef MULTI_THREADE_TRACKER_H
#define MULTI_THREADE_TRACKER_H
#include"basedetector.h"
#include"Ctracker.h"
#include<thread>
#include<memory>
#include<vector>
#include<mutex>
#include"atomicops.h"
#include"readerwriterqueue.h"
#include"opencv2\opencv.hpp"

class Multi_Thread_Tracker
{
	using detect_result = std::pair<std::vector<Point_t>, std::vector<CRegion>>;
public:
	Multi_Thread_Tracker(std::unique_ptr<PersonDetector>& detector_, std::shared_ptr<CTracker>& tracker_):detect_queue(1)
	{
		detector = std::move(detector_);
		tracker = tracker_;

		std::thread detectionThread(&Multi_Thread_Tracker::detect, this);
		detectionThread.detach();
	}

	void update(cv::Mat image);

	~Multi_Thread_Tracker()
	{

	}

private:
	void detect();

private:
	cv::Mat shared_frame;
	std::unique_ptr<PersonDetector> detector;
	std::shared_ptr<CTracker> tracker;

	moodycamel::ReaderWriterQueue<detect_result> detect_queue;
	std::mutex frame_mutex;
};


#endif // !MULTI_THREADER_TRACKER_H
